<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<jsp:include page="global.jsp"></jsp:include>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>收件箱</title>
<style type="text/css">
.ctl{
	text-decoration: none;
	color: blue;
	margin: auto 7px;
}
.ctl:HOVER{
	text-decoration: underline;
}
.center{
	text-align: center;
}
</style>
</head>
<body>
	<table id="dg" class="easyui-datagrid" title="收件箱"
			data-options="
				rownumbers:true,
				iconCls: 'icon-edit',
				singleSelect: true,
				toolbar: '#tb',
				singleSelect:true,
				pagination:true,
				fit:true,
				fitColumns:true,
				pageList:[20,25,30,35,40,45,50],
				pageSize:20
			">
		<thead>
			<tr>
				<th data-options="field:'senderName',width:50, align:'center'">发件人</th>
				<th data-options="field:'receiveTime',width:90, align:'center'">发件时间</th>
				<th data-options="field:'status',width:50, align:'center'">状态</th>
				<th data-options="field:'messageContent',width:360,align:'center'">消息内容</th>
				<th data-options="field:'id',width:50,align:'center',formatter:formatControl">管理</th>
			</tr>
		</thead>
	</table>

	<div id="tb" style="height:auto">
		<div>								
			发件人：
			<select data-options="editable: false" id = "sender" class="easyui-combobox">
				<option value = "-1"> --全部-- </option>
				<c:forEach var="item" items="${peoples }" >
					<c:if test="${item.id != currentUser.id }">
						<option value = "${item.id }">${item.name }</option>
					</c:if>
				</c:forEach>
			</select>			
			消息内容: <input class="easyui-textbox" type="text" id="messageContent" style="width:220px;height:25px;">	
			发件时间：<input class="easyui-datetimebox"  id="receiveTimeBegin" style="width:200px;height:25px;">
			至  <input class="easyui-datetimebox"  id="receiveTimeEnd" style="width:200px;height:25px;">
			
			<a href="javascript:search()" class="easyui-linkbutton" iconCls="icon-search">查 找</a>
		</div>
	</div>
	
	<div id="lookDetail" class="easyui-window" title="消息详情" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:620px; height:300px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<table width="100%" height="100%">
					<tr>
						<td align="right">发件人：</td>
						<td>
							<input class="easyui-textbox" id="lookSender" style="width: 150px;" readonly="readonly">
						</td>
						<td align="right">发件时间：</td>
						<td>
							<input class="easyui-datetimebox" id="lookReceiveTime" style="width: 200px;" readonly="readonly">
						</td>						
					</tr>
					<tr>
						<td align="right">消息内容：</td>
						<td colspan="3">
							<input class="easyui-textbox" id="lookMessageContent" style="width: 470px; height: 120px;" data-options="multiline:true" readonly="readonly" />
						</td>
					</tr>
					
				</table>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="javascript:$('#lookDetail').window('close');$('#dg').datagrid('reload');" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<script type="text/javascript">
		function formatControl(val, row){
			return '<a class="ctl" href="javascript:void(0)" onclick="lookDetail(' + val + ')">查看</a>'+
			' <a class="ctl" href="javascript:void(0)" onclick="delItem(' + val + ')">删除</a>';
		}
		function search(){
			var dg = $("#dg");
			var sender = $("#sender").combobox("getValue");
			var receiveTimeBegin = $("#receiveTimeBegin").textbox("getValue").trim();	
			var receiveTimeEnd = $("#receiveTimeEnd").textbox("getValue").trim();
			var messageContent = $("#messageContent").textbox("getValue").trim();
			
			
			var url = "queryMyInbox?messageContent="+messageContent + "&receiveTimeBegin=" + receiveTimeBegin+ "&receiveTimeEnd=" + receiveTimeEnd+ "&senderId=" + sender;
			
			dg.datagrid('reload', url);
			
		}
		function lookDetail(id){
			var pparams = "id=" + id;
			$.ajax({
				type: "GET",
			  	url: "findOneInbox",
			  	data: pparams,
			  	success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						var item = val.data;
						
						$("#lookPerson").combobox("setValue", item.personId);
						$("#lookSender").textbox("setValue", item.senderName);
						$("#lookReceiveTime").textbox("setValue", item.receiveTime);
						$("#lookMessageContent").textbox("setValue", item.messageContent);
						$("#lookStatus").textbox("setValue", item.status);
						
						$('#lookDetail').window('open');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
			  	}
			});

			var params = "id=" + id + "&status=0065";
			$.ajax({
				type: "GET",
				url: "readedInbox",
				data: params,
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						
					}
				}
			});
		}
		function editItem(id, personId, senderId, receiveTime, messageContent, status){
			$("#editId").val(id);			
			$("#editPerson").combobox("setValue", personId);
			$("#editSender").combobox("setValue", senderId);
			$("#editReceiveTime").textbox("setValue", receiveTime);			
			$("#editMessageContent").textbox("setValue", messageContent);
			$("#editStatus").textbox("setValue", status);
			
			$('#editItem').window('open');
		}
		function delItem(id){
			$.messager.confirm("删除确认", "您确定要删除所选的消息吗？", function(r){
				if(r){
					params = "id=" + id;
					$.ajax({
					  type: "GET",
					  url: "delInbox",
					  data: params,
					  success:function(data){
						var val = $.parseJSON(data);
						if(val.success){
							bottomRight('提示', '操作成功！');
							$('#dg').datagrid('reload');
						}else{
							$.messager.alert("提示", val.msg, "error");
						}
					  }
					});
				}
			});
		}
		$(function(){
			$("#form").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						$('#dg').datagrid('reload');
						bottomRight('提示', '操作成功！');
						$('#addItem').window('close');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});
			$("#editForm").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						$('#dg').datagrid('reload');
						bottomRight('提示', '操作成功！');
						$('#editItem').window('close');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});
			search();
		});
	</script>
</body>
</html>